//
//  FoundViewController.m
//  WE
//
//  Created by 要帅气的生活 on 15/11/18.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "FoundViewController.h"
#import "Head.h"
#import "NutritionViewController.h"
#import "ScanViewController.h"
#import "ModelCrowdViewController.h"
#import "HealthLookControl.h"
#import "DoctorDynamicControl.h"
#import <UIImageView+WebCache.h>
@interface FoundViewController ()<ScanQRCodeDelegate>
@property (nonatomic, strong)UITableView * tableView;

@end

@implementation FoundViewController
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
    UIView *searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 63)];
    searchView.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
    [self.view addSubview:searchView];
    [ToolUtil createLine:63 superView:self.view lift:0 width:WindowWidth hight:1 color:[UIColor grayColor]];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, WindowWidth, 43)];
    label.text = @"发现";
   // label.font = [UIFont boldSystemFontOfSize:17.0f];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor blackColor];
    [searchView addSubview:label];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    NSURLConnection
    [self creatView];
//    [self.view addSubview:self.tableView];
////    [self setExtraCellLineHidden:self.tableView];
//    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
//        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
//    }
//    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
//        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
//    }
}

- (void)creatView
{
    UIImageView * aImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, margin_64 * Width, WindowWidth, 120 * Height)];
    aImageV.backgroundColor = DEBUG_CLOLR;
    [aImageV sd_setImageWithURL:[NSURL URLWithString:@"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg"]];
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(0, CGRectGetMaxY(aImageV.frame) + 20*Height, WindowWidth, 55*Height);
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag = 150 ;
    
    UIImageView * bImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 25, 25)];
    bImageV.backgroundColor = DEBUG_CLOLR;
//    [bImageV sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg"]];

    UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(bImageV.frame) + 10, 0, 90, 20)];
    lbl.text = @"医生动态";
    lbl.font = FONT(14);
    
    UILabel * lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(bImageV.frame) + 10, CGRectGetMaxY(lbl.frame), 190, 20)];
    lbl1.text = @"掌握医生动态, 合理安排就医";
    lbl1.font = FONT(12);
    lbl1.textColor = [UIColor grayColor];
    
    [btn addSubview:bImageV];
    [btn addSubview:lbl];
    [btn addSubview:lbl1];
    
    [ToolUtil createLine:CGRectGetMaxY(aImageV.frame) superView:self.view lift:0 width:WindowWidth hight:10 color:GRAYCOLOR];
    float y = [ToolUtil createLine:CGRectGetMaxY(btn.frame) superView:self.view lift:0 width:WindowWidth hight:10 color:GRAYCOLOR];
    [self.view addSubview:aImageV];
    [self.view addSubview:btn];
    NSArray * arr = @[@"健康自诊",@"疾病库",@"扫一扫",@"疾病与营养"];
    NSArray * arr1 = @[@"自测问题及早排忧",@"易用全面的疾病百科",@"添加信任的医生",@"合理搭配远离疾病"];
    int count = 0;
    for (int i = 0; i < 2; i++) {
        for (int j= 0; j < 2; j++) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            
            btn.frame = CGRectMake(j * (WindowWidth/2 - 1) + j * 1, y + i * 55 + i * 1, WindowWidth/2 -1, 55);
            btn.tag = 100+ i*10 + j;
//            btn.backgroundColor = DEBUG_CLOLR;
            [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
            UIImageView * bImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 25, 25)];
            bImageV.backgroundColor = DEBUG_CLOLR;
            
            UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(bImageV.frame) + 10, 5, 90*Width, 20*Height)];
            lbl.text = arr[count];
            lbl.font = FONT(14);
            
            UILabel * lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(bImageV.frame) + 10, CGRectGetMaxY(lbl.frame), 120*Width, 40*Height)];
            lbl1.text = arr1[count];
            lbl1.font = FONT(12);
            lbl1.numberOfLines = 0;
            lbl1.textColor = [UIColor grayColor];
            count++;
            [btn addSubview:bImageV];
            [btn addSubview:lbl];
            [btn addSubview:lbl1];
            [self.view addSubview:aImageV];
            [self.view addSubview:btn];
        }
    }
    [ToolUtil createLine:y+55 superView:self.view lift:0 width:WindowWidth hight:1 color:GRAYCOLOR];
    [ToolUtil createVerticalLine:y superView:self.view lift:WindowWidth/2-1 height:111]
    ;
    [ToolUtil createLine:y+111 superView:self.view lift:0 width:WindowWidth hight:WindowHeight - 111 color:GRAYCOLOR];

//    NSArray * arr = @[@"健康自诊",@"疾病库",@"扫一扫"];
//    for (int i = 0; i < 3; i++) {
//        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(20 + i * 40 + i *(WindowWidth - 120)/3 , 80, (WindowWidth - 120)/3, 150);
//        [button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
//        button.tag = 100 + i;
//        UIImageView * aImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,(WindowWidth - 120)/3 , (WindowWidth - 120)/3)];
//            aImageView.image = [UIImage imageNamed:@""];
//        aImageView.backgroundColor = DEBUG_CLOLR;
//        aImageView.layer.masksToBounds = YES;
//        aImageView.layer.cornerRadius = (WindowWidth - 120)/3/2;
//            UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(aImageView.frame) + margin_5, (WindowWidth - 120)/3, margin_20)];
//            lbl.font = FONT(14);
//            lbl.text = arr[i];
//            lbl.textAlignment = NSTextAlignmentCenter;
//            [button addSubview:aImageView];
//            [button addSubview:lbl];
//        [self.view addSubview:button];
//    }
}
- (void)clickBtn:(UIButton *)btn
{
    if (btn.tag == 100) {
        NSLog(@"自诊");
        [self.navigationController pushViewController:[[HealthLookControl alloc] init] animated:YES];
        
    }else if (btn.tag == 101){
        NSLog(@"疾病率");
        [self.navigationController pushViewController:[[ModelCrowdViewController alloc] init] animated:YES];
    }else if (btn.tag == 110){
        NSLog(@"扫一扫");
        ScanViewController * scanVC = [[ScanViewController alloc] init];
        scanVC.delegate = self;
        [self.navigationController pushViewController:scanVC animated:YES];
        
    }else if (btn.tag == 111){
        NSLog(@"疾病与营养");
        NutritionViewController * nutVC = [[NutritionViewController alloc] init];
        [self.navigationController pushViewController:nutVC animated:YES];
    }else if (btn.tag == 150){
        [self.navigationController pushViewController:[[DoctorDynamicControl alloc] init] animated:YES];
    }
    
    
}
- (void)scanResult:(NSString *)result
{
    NSLog(@"%@",result);
}


@end
